home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,gnu.gcc.help
- Path: info.physics.utoronto.ca!olivers
- From: olivers@helios.physics.utoronto.ca (Oliver Schonborn)
- Subject: [Q] WEIRD macro bug only when compiling with GCC
- Message-ID: <DLKABL.KGK@info.physics.utoronto.ca>
- Nntp-Posting-Host: helios.physics.utoronto.ca
- Sender: news@info.physics.utoronto.ca (System Administrator)
- Organization: University of Toronto - Dept. of Physics
- Date: Mon, 22 Jan 1996 02:45:21 GMT
-
-
- Hi folks, I defined the following macro, *which works
- FINE* with the HP cc compiler:
-
- #define SQR(X,A) (A=(X),(A*A))
-
- I call it for example by
-
- float ans,f,dx,dy;
- int i,j;
- dx=1;dy=0.335389;
- for (i=0;i<10;i++) {
- for (j=0;j<10;j++) {
- ans = SQR( i*dx, f) + SQR( j*dy, f);
- }
- }
-
- The macro *works FINE* when I compile with our HP compiler,
- cc: it prints out one hundred different numbers. BUT when
- I use gcc to compile, instead what it prints is double the
- result of the first SQR on the line, ie SQR( i*dx, f) * 2.
- Why isn't (a=b, b*b)+(a=c, c*c) equal to b*b+c*c for GCC?
-
- Although I've decided to implememt the macro by a function
- instead (float sqr(float x) {return x*x;}), I'm curious to
- know what is wrong with the macro I wrote. Anyone have a
- clue?
-
- Thanks a lot!
-
- Oliver
- --
- _________________________________........----------------,
- /\ OliverS@physics.utoronto.ca \
- \_| Condensed-Matter/Quantum-Optics Theory Group )
- / Physics Dept University of Toronto -- Canada /
-